package com.ronglian.ucdisk.share.service.impl;

import java.util.List;
import java.util.UUID;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.ronglian.ucdisk.test.Department;
import com.ronglian.ucdisk.test.Employee;

@Repository(value="TestService")
public class TestService {

	@PersistenceContext 
	public EntityManager em ;
	
	
	@Transactional
	public void test_() {
		// TODO Auto-generated method stub
		Department depart = new Department();
		depart.id = UUID.randomUUID().toString();
		depart.name ="develop" ; 
		//depart.employList = new ArrayList<Employee>(); 
		em.persist(depart);
		for(int i = 0 ; i< 2 ; i++) {
			Employee e = new Employee(); 
			e.id = UUID.randomUUID().toString();
			//.departmentId  = depart.id; 
			e.department = depart ;
			e.name = "baipeng";
			em.persist(e);
		}
	} 
	@Transactional
	public void test() {
		//加上级联的情况
		Department depart = em.find(Department.class, "ce404879-3cb2-4f90-857a-33c6e1543c53");
		
		List<Employee> elist = depart.getEmployList();
		Employee e = new Employee(); 
		e.id = UUID.randomUUID().toString();
		//.departmentId  = depart.id; 
		e.department = depart ;
		e.name = "baipeng_new";
		
		elist.add(e);
		em.persist(e);
	}
	
}
